/*     */ package com.java.diagnostics.visualizer.parser.vgc.sovereign;
/*     */ 
/*     */ import java.io.BufferedReader;
/*     */ import java.io.IOException;
/*     */ import java.util.regex.Matcher;
/*     */ import java.util.regex.Pattern;
/*     */ 
/*     */ public abstract class LineFixer
/*     */ {
/*  46 */   private static LineFixer[] fixers = { 
/*  47 */     new LostCountAFLineFixer(), 
/*  48 */     new MisConvertedEBCDICFixer() };
/*     */ 
/*     */   public static BufferedReader wrapReader(BufferedReader r)
/*     */   {
/*  52 */     return new FixingBufferedReader(r);
/*     */   }
/*     */ 
/*     */   protected abstract String fixLine(String paramString, FixingBufferedReader paramFixingBufferedReader);
/*     */ 
/*     */   private static String fixUpLine(String line, FixingBufferedReader r)
/*     */   {
/*  59 */     if (line == null) {
/*  60 */       return null;
/*     */     }
/*  62 */     for (int i = 0; i < fixers.length; i++) {
/*  63 */       line = fixers[i].fixLine(line, r);
/*     */     }
/*  65 */     return line;
/*     */   }
/*     */ 
/*     */   private static class FixingBufferedReader extends BufferedReader
/*     */   {
/*  70 */     private int fix_count = 0;
/*     */ 
/*     */     FixingBufferedReader(BufferedReader r) {
/*  73 */       super(r);
/*     */     }
/*     */     public String readLine() throws IOException {
/*  76 */       return LineFixer.fixUpLine(super.readLine(), this);
/*     */     }
/*     */   }
/*     */ 
/*     */   private static class LostCountAFLineFixer extends LineFixer
/*     */   {
/* 132 */     static final Pattern brokenAF = Pattern.compile(
/* 133 */       "(^ *<AF)([0-9]*)(:.*$)");
/*     */ 
/*     */     public String fixLine(String line, LineFixer.FixingBufferedReader r)
/*     */     {
/* 141 */       if (line == null) {
/* 142 */         return null;
/*     */       }
/* 144 */       Matcher matchBrokenAF = brokenAF.matcher(line);
/* 145 */       if (matchBrokenAF.matches())
/*     */       {
/* 147 */         String newline = matchBrokenAF.group(1) + "[" + 
/* 148 */           matchBrokenAF.group(2) + "]" + matchBrokenAF.group(3);
/*     */ 
/* 153 */         r.fix_count += 1;
/* 154 */         return newline;
/*     */       }
/* 156 */       return line;
/*     */     }
/*     */   }
/*     */ 
/*     */   private static class MisConvertedEBCDICFixer extends LineFixer
/*     */   {
/*  93 */     static final String openSquareBracket = Character.valueOf('Ý').toString();
/*  94 */     static final String closeSquareBracket = Character.valueOf('¨').toString();
/*  95 */     static final Pattern openPattern = Pattern.compile(".*" + openSquareBracket + ".*");
/*  96 */     static final Pattern closePattern = Pattern.compile(".*" + closeSquareBracket + ".*");
/*     */ 
/*     */     public String fixLine(String originalLine, LineFixer.FixingBufferedReader r)
/*     */     {
/* 100 */       String line = originalLine;
/*     */ 
/* 104 */       Matcher openMatcher = openPattern.matcher(originalLine);
/* 105 */       Matcher closeMatcher = closePattern.matcher(originalLine);
/* 106 */       if ((openMatcher.matches()) && (closeMatcher.matches())) {
/* 107 */         line = originalLine.replaceAll(openSquareBracket, "[");
/* 108 */         line = line.replaceAll(closeSquareBracket, "]");
/* 109 */         r.fix_count += 1;
/*     */       }
/* 111 */       return line;
/*     */     }
/*     */   }
/*     */ }

